package com.hdu.hot100.backTrack;

import java.util.ArrayList;
import java.util.List;

public class lc46 {
    class Solution {

        List<List<Integer>> ans = new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        boolean[] used;

        public List<List<Integer>> permute(int[] nums) {
            used = new boolean[nums.length];
            f(nums);
            return ans;
        }

        void f(int[] nums)
        {
            if (path.size() == nums.length)
            {
                ans.add(new ArrayList<>(path));
                return;
            }
            for (int i = 0; i < nums.length; i++)
            {
                if (used[i])
                {
                    continue;
                }
                path.add(nums[i]);
                used[i] = true;
                f(nums);
                path.remove(path.size() - 1);
                used[i] = false;
            }
        }
    }
}
